package com.car.account.controller;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.car.account.controller.form.storesEntryForm.AdminSelectEntryForm;
import com.car.account.controller.form.storesEntryForm.EntryApplicationForm;
import com.car.account.controller.form.storesEntryForm.OverruleApplicationForm;
import com.car.account.dto.storesEntryDto.StoresEntryByIdDto;
import com.car.account.dto.storesEntryDto.StoresEntryDto;
import com.car.account.param.storesEntryParam.AdminSelectEntryParam;
import com.car.account.service.StoresEntryApplicationService;
import com.car.commons.core.model.Result;
import com.car.commons.core.util.JwtUtil;
import com.car.commons.web.util.WebUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 董旭
 * @since 2024-08-28
 */
@RestController
@RequestMapping("/storesEntryApplication")
@Api(tags = "门店入驻申请")
public class StoresEntryApplicationController {

    @Resource
    private StoresEntryApplicationService storesEntryApplicationService;

    @PostMapping("/adminSelectStoresEntryDto")
    @ApiOperation(value = "超管根据入驻申请姓名，手机号，状态查询申请信息")
    public Result<Page> adminSelectStoresEntryDto(@RequestBody AdminSelectEntryForm form) throws Exception{
        String token = WebUtil.getRequest().getHeader("car-token");
        Integer adminId = JwtUtil.getAdminId(token);
        AdminSelectEntryParam param = BeanUtil.toBean(form, AdminSelectEntryParam.class);
        param.setAdminId(adminId);
        Page<StoresEntryDto> page = storesEntryApplicationService.adminSelectStoresEntryDto(param);
        return Result.getResult(Page.class)
                .setData(page)
                .setMsg("超管查询入驻申请信息成功");
    }

    @GetMapping("/adminSelectById")
    @ApiOperation(value = "超管根据id查询申请信息")
    public Result<StoresEntryByIdDto> adminSelectById(Integer applicationId) throws Exception{
        String token = WebUtil.getRequest().getHeader("car-token");
        Integer adminId = JwtUtil.getAdminId(token);
        StoresEntryByIdDto dto = storesEntryApplicationService.adminSelectById(adminId, applicationId);
        return Result.getResult(StoresEntryByIdDto.class).setData(dto).setMsg("超管根据id查询申请信息成功");
    }

    @PostMapping("/entryApplication")
    @ApiOperation(value = "门店入驻申请")
    public Result entryApplication(@RequestBody EntryApplicationForm form) throws Exception{
        storesEntryApplicationService.entryApplication(form);
        return Result.getResult().setMsg("门店入驻申请成功");
    }

    @GetMapping("/passApplicationById")
    @ApiOperation(value = "超管通过门店入驻申请")
    public Result passApplicationById(Integer applicationId)throws Exception{
        String token = WebUtil.getRequest().getHeader("car-token");
        Integer adminId = JwtUtil.getAdminId(token);
        storesEntryApplicationService.passApplicationById(adminId, applicationId);
        return Result.getResult().setMsg("超管通过入驻申请成功");
    }

    @GetMapping("/overruleApplicationById")
    @ApiOperation(value = "超管驳回门店入驻申请")
    public Result overruleApplicationById(@RequestBody OverruleApplicationForm form)throws Exception{
        String token = WebUtil.getRequest().getHeader("car-token");
        Integer adminId = JwtUtil.getAdminId(token);
        storesEntryApplicationService.overruleApplicationById(adminId, form);
        return Result.getResult().setMsg("超管驳回入驻申请成功");
    }

}

